﻿namespace GSC.WebControls
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI.Design;
    using System.Web.UI.Design.WebControls;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.IO;
    using System.ComponentModel.Design;
    using System.Web.UI.HtmlControls;
    sealed class BackgroundCenterLeftMenuButtonControlDesigner : ControlDesigner
    {
        private BackgroundCenterLeftMenuButtonControl _LeftMenuButton;

        /// <summary>
        /// </summary>
        /// <param name="Component"></param>
        public override void Initialize(IComponent Component)
        {
            base.Initialize(Component);
            this._LeftMenuButton = (BackgroundCenterLeftMenuButtonControl)Component;
        }
        bool _isComponentChanged = false;
        public override void OnComponentChanged(object sender, ComponentChangedEventArgs ce)
        {
            base.OnComponentChanged(sender, ce);
            if (!this._isComponentChanged)
            {
                switch (ce.Member.Name)
                {
                    case "IsSelected":
                        this._isComponentChanged = true;
                        if ((bool)ce.NewValue)
                        {
                            if (this._LeftMenuButton.Parent != null &&
                                this._LeftMenuButton.Parent.Parent != null &&
                                this._LeftMenuButton.Parent.Parent.Parent != null &&
                                this._LeftMenuButton.Parent.Parent.Parent is BackgroundCenterLeftMenuControl)
                            {
                                foreach (BackgroundCenterLeftMenuTitleControl item in ((BackgroundCenterLeftMenuControl)this._LeftMenuButton.Parent.Parent.Parent).Titles)
                                {
                                    foreach (BackgroundCenterLeftMenuButtonControl citem in item.Buttons)
                                    {
                                        citem.IsSelected = false;
                                    }
                                }
                                this._LeftMenuButton.IsSelected = true;
                            }
                            else if (this._LeftMenuButton.Parent != null &&
                                this._LeftMenuButton.Parent.Parent != null &&
                                this._LeftMenuButton.Parent.Parent.Parent != null &&
                                this._LeftMenuButton.Parent.Parent.Parent.Parent != null &&
                                this._LeftMenuButton.Parent.Parent.Parent.Parent.Parent != null &&
                                this._LeftMenuButton.Parent.Parent.Parent.Parent.Parent.Parent != null &&
                                this._LeftMenuButton.Parent.Parent.Parent.Parent.Parent.Parent.Parent is BackgroundControl)
                            {
                                foreach (BackgroundCenterLeftMenuTitleControl item in ((BackgroundControl)this._LeftMenuButton.Parent.Parent.Parent.Parent.Parent.Parent.Parent).CenterLeftMenuTitles)
                                {
                                    foreach (BackgroundCenterLeftMenuButtonControl citem in item.Buttons)
                                    {
                                        citem.IsSelected = false;
                                    }
                                }
                                this._LeftMenuButton.IsSelected = true;
                            }
                        }
                        break;
                }
                this._isComponentChanged = false;
            }
        }
        public override void OnComponentChanging(object sender, ComponentChangingEventArgs ce)
        {
            base.OnComponentChanging(sender, ce);
        }
    }
}
